<template>
  <div>
    <div class="head-top">
      <mt-header title="期刊详情列表">
        <mt-button icon="back" slot="left" @click='back'></mt-button>
      </mt-header>
    </div>
    <div class="main">
      <div class="cell">
        <div v-for="(item,index) in perlist" :key="index" @click="goToRead(item)">
          <p class="time"><img src="../../../../../static/yuan.png" alt="">{{item.external_source_name}}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "./../../../../api/api.js";
import baseurl from "../../../../api/baseurl.js"
import { Indicator } from "mint-ui";

export default {
  data() {
    return {
      typeName: "",
      source: "",
      period: "",
      perlist: []
    };
  },
  created() {
    this.period = JSON.parse(this.$route.params.period);
    const source = localStorage.getItem("source"); //取
    this.source = JSON.parse(source);
    this.getPerfour();
  },
  methods: {
    // 行为记录
    readRecord(e) {
      const userid = localStorage.getItem("userid");
      const accid = localStorage.getItem("accid");
      const params = new URLSearchParams();
      params.append("title", e.external_source_name);
      params.append("type", 5);
      params.append("userid", userid);
      params.append("fileid", this.source);
      params.append("recorddate", "");
      params.append("describ", e.file_name);
      params.append("imgurl", "");
      params.append("author","");
      params.append("edition", accid);
      this.$http({
        method: "post",
        url: baseurl.urls + "readrecord/addReadrecord",
        data: params
      })
        .then(response => {
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
    },
    goToRead(e) {
      this.readRecord(e);
      let imgSrc = api.PdfSrc;
      let str = e.file_name.substring(0, 10);
      this.$router.push({
        name: "readingPdf",
        params: {
          bookurl: imgSrc + "/skjc_qk/" + str + "/" + e.file_name + ".pdf",
          bookName: e.external_source_name
        }
      });
    },
    back() {
      this.$router.back(-1);
    },
    getPerfour() {
      const userid = localStorage.getItem("userid");
      Indicator.open({
        text: "拼命加载中...",
        spinnerType: "triple-bounce"
      });
      this.$http({
        method: "post",
        url: api.baseURL + "getCnkiGroupInformation",
        params: {
          inParam: {
            group: ["external_source_name", "file_name"],
            constraint: [
              {
                name: "source",
                value: this.source
              },
              {
                name: "period",
                value: this.period
              }
            ],
            time: this.datevalue,
            userId: userid,
            pageSize: 10,
            currentPage: 1,
            resourceType: 5,
            maxvalue: [],
            sysCode: "FH_PUBOPE"
          }
        }
      })
        .then(response => {
          if (response.status == 200) {
            this.perlist = response.data.data;
            console.log(this.perlist)
            Indicator.close();
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style>
.main .cell {
  margin-top: 16px;
  margin-bottom: 65px;
}
.main .time {
  width: 100%;
  height: 45px;
  background: #fff;
  margin-top: 2px;
  line-height: 45px;
  padding: 0 10px;
  box-sizing: border-box;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.time > img {
  margin-right: 10px;
}
</style>